package com.portal.portal.config.service;

import java.io.InputStream;
import java.util.Set;

import javax.servlet.ServletContext;

import com.portal.portal.config.DriverResourceConfig;
import com.portal.portal.config.ResourceConfigReader;
import com.portal.util.constants.ServletAttributeKeys;
import com.portal.util.exception.PortalDriverConfigurationException;

public class DriverBasicInfoServiceImpl implements DriverBasicInfoService {

  private DriverResourceConfig driverResourceConfiguration;

  public void destroy() throws PortalDriverConfigurationException {
    //ctx.setAttribute(ServletAttributeKeys.DRIVER_RENDER_CONFIG, null);
  }

  public void init(ServletContext ctx) throws PortalDriverConfigurationException {
    try {
      InputStream in = ctx.getResourceAsStream(ResourceConfigReader.DRIVER_CONFIG_FILE);
      driverResourceConfiguration = ResourceConfigReader.getFactory().parse(in);
      ctx.setAttribute(ServletAttributeKeys.DRIVER_RENDER_CONFIG, driverResourceConfiguration.getDriverRenderConfig());
      ctx.setAttribute(ServletAttributeKeys.DRIVER_RESOURCE_CONFIG, driverResourceConfiguration);
    } catch (Exception e) {
      throw new PortalDriverConfigurationException(e);
    }
  }

  public String getPortalName() {
    return driverResourceConfiguration.getPortalName();
  }

  public String getPortalVersion() {
    return driverResourceConfiguration.getPortalVersion();
  }

  public String getContainerName() {
    return driverResourceConfiguration.getContainerName();
  }

  public Set<String> getSupportedPortletModes() {
    return driverResourceConfiguration.getSupportedPortletModes();
  }

  public Set<String> getSupportedWindowStates() {
    return driverResourceConfiguration.getSupportedWindowStates();
  }

}
